package com.ruoyi.ruoyiqywechat.wx.pay.config;

import com.wechat.pay.contrib.apache.httpclient.util.PemUtil;

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.Signature;
import java.security.SignatureException;
import java.util.Base64;

/**
 * @author yhw
 * @date 2023/11/9
 * @apiNote 对预订单的信息进行加密得到最终的签名
 */
public class SignCryptoText {
    public static String sign(byte[] message) throws NoSuchAlgorithmException, SignatureException, InvalidKeyException {
        Signature sign = Signature.getInstance("SHA256withRSA");
        sign.initSign(PemUtil.loadPrivateKey(PayConstants.PRIVATE_KEY));
        sign.update(message);
        return Base64.getEncoder().encodeToString(sign.sign());
    }

}
